package io.shallwe.stovingoven;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;
import io.shallwe._admin.auth.AdminAuthInterceptor;
import io.shallwe.common.model.Account;

/**
 * 烘干炉温度控制参数修改校验器
 * @author 王小伟
 * @date 2019-07-10 13:40:04
 **/
public class StovingOvenTemperatureValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        setShortCircuit(true);
        setRet(Ret.fail());
        Account threadLocalAccount = AdminAuthInterceptor.getThreadLocalAccount();
        if(threadLocalAccount==null){
            addError("msg","未登录的用户不能修改！");
        }

        validateRequired("stovingOven.id","msg","数据不完整");
        validateRequired("stovingOven.maxCount","msg","必须填写连续空筐数量上限");
        validateRequired("stovingOven.configStatus","msg","必须设置状态");
        validateRequired("stovingOven.riseTag","msg","必须设置升温点");
        validateRequired("stovingOven.downTag","msg","必须设置降温点");

        validateInteger("stovingOven.id","msg","数据不完整");
        validateInteger("stovingOven.maxCount","msg","必须填写连续空筐数量上限");
        validateInteger("stovingOven.configStatus","msg","必须设置状态");
        validateRequiredString("stovingOven.riseTag","msg","升温点填写有误");
        validateRequiredString("stovingOven.downTag","msg","降温点填写有误");
    }

    @Override
    protected  void handleError(Controller controller){
        controller.renderJson(getRet());
    }
}
